//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "editor\fn_protectVehicle.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_multiplier"];
DEFAULT_PARAM(_object,0,objNull);

if !(isNull _object) then {
	_object addEventHandler ["HandleDamage",{
		if ((_this select 1) == "") then {
			private ["_dmg","_prev"];
			_dmg = _this select 2;
			// unit, selectionName, damage, source, projectile 
			if ((isPlayer(_this select 3)) || {(_this select 4) != ""} || {(!(isNull (_this select 3)) && {(side (_this select 3) != side (crew (_this select 0) select 0))})}) then {
				TRACE_1("Let damage pass",_this);
				(_this select 0) setVariable [QGVAR(PREVIOUS_DAMAGE), _dmg];
			} else {
				TRACE_1("Negate damage",_this);
				_prev = (_this select 0) getVariable [QGVAR(PREVIOUS_DAMAGE), _dmg];
				_dmg = _prev;
			};
			_dmg;
		};
	}];
};
TRACE("End");
TMFPROFILERSTOP;